home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Includes / UPopup.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  7.6 KB  |  221 lines  |  [TEXT/MPS ]

  1. // UPopup.h
  2. // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UPOPUP__
  5. #define __UPOPUP__
  6.  
  7. //----------------------------------------------------------------------------------------
  8. // Theory of Operation
  9. // ===================
  10. //
  11. // This unit allows Popup menus to be instantiated which are managed by the Popup CDEF,
  12. // included in System 7.0 and in the installer script for the Communications Toolbox.
  13. //    
  14. // To use this Unit and the Popup CDEF with MacApp applications that run under System 6.x,
  15. // the Popup CDEF will need to be included in the application's resource fork.
  16. //    
  17. // This unit actually extends the capabilities provided by the Popup CDEF as follows:
  18. //        allows for non resource-based MENUs
  19. //        allows for hierarchical popups
  20. //    
  21. //    
  22. // Usage
  23. // =====
  24. //
  25. // For Sys 6.0 support: include the Popup CDEF in the resource fork of your application
  26. // with the following lines in your app.r file:
  27. //        include "Popup.rsrc";
  28. //    
  29. // Also, include either the CMNU or MENU resource in your application's resource fork.
  30. //
  31. // To handle the command number associated with the selected item in the popup, include
  32. // code such as the following in the holding view (e.g. a TDialogView subclass) or in the
  33. // document (this code was taken from DemoDialogs):
  34. //
  35. //        void TTestDialogView::DoEvent(EventNumber eventNumber...) // override 
  36. //        
  37. //        {
  38. //            if ((eventNumber == mPopupHit) && (source == fMyPopup))
  39. //            {
  40. //                aCommandNumber = ((TPopup*)source)->GetCurrentCommand();
  41. //                switch (aCommandNumber)
  42. //                {
  43. //                    case cMyCommand:
  44. //                    {
  45. //                    }
  46. //                }
  47. //            }
  48. //        }
  49. //    
  50. // Limitations
  51. //
  52. // The first item in the popup can't be a hierarchical menu. This is actually a bug in the
  53. // Popup CDEF as it exists in System 7.0b1 and earlier versions (including the Comm
  54. // Toolbox release). A bug report has been filed with SQA.
  55. //----------------------------------------------------------------------------------------
  56.  
  57. // MacApp
  58.  
  59. #ifndef __UCONTROL__
  60. #include "UControl.h"
  61. #endif
  62.  
  63. //----------------------------------------------------------------------------------------
  64. // Forward and external class declarations
  65. //----------------------------------------------------------------------------------------
  66.  
  67.  
  68. //----------------------------------------------------------------------------------------
  69. // Constants
  70. //----------------------------------------------------------------------------------------
  71.  
  72. const    Boolean        kUseAddResMenu    = TRUE;
  73. const    Boolean        kDontUseAddResMenu    = !kUseAddResMenu;
  74.             
  75.  
  76. //----------------------------------------------------------------------------------------
  77. // TPopup: supports a simple popup with minimal support for hierarchical popups.
  78. //----------------------------------------------------------------------------------------
  79.  
  80. class TPopup : public TCtlMgr                    // A typical popup menu.
  81. {
  82.     MA_DECLARE_CLASS;
  83.     
  84. public:
  85.     TPopup();
  86.         // Empty constructor to satisfy compiler.
  87.         
  88.     void IPopup(TView*                 itsSuperView,
  89.                    const VPoint&    itsLocation, 
  90.                    const VPoint&    itsSize,
  91.                    SizeDeterminer    itsHSizeDet,
  92.                    SizeDeterminer    itsVSizeDet,
  93.                    short            itsMenuID,                // rsrc ID of 'MENU' or 'CMNU' rsrc 
  94.                    short            itsCurrentItem,
  95.                    short            itsItemOffset,            // width of the popup title area 
  96.                    short            itsStrListID,            // popup's title:    STR# rsrc id
  97.                    short            itsIndex,                //                    index into STR#
  98.                    /* Style */ short itsStyle,                // title's style 
  99.                    short            itsJust,                // title's justification 
  100.                    Boolean            useAddResMenu,            // true if want to AddResMenu (can use
  101.                                                             // this option iff menuID != kNoResource)
  102.                    ResType            useAddResMenuResType,    // used if useAddResMenu is true
  103.                    const TextStyle& itsTextStyle = gSystemStyle);// popup's text style
  104.         // Initializes the popup.
  105.         
  106.     virtual ~TPopup();
  107.  
  108.     virtual unsigned short GetPopupTitleStyle();
  109.         // map fTitleStyle and fTitleJust to popupTitleStyle.
  110.  
  111.     virtual short GetProcID();
  112.         // return the appropriate proc id
  113.  
  114.     virtual void CreateCMgrControl(const CStr255&    itsTitle,
  115.                                           long        itsVal,
  116.                                           long        itsMin,
  117.                                           long        itsMax,
  118.                                           short     itsProcID); // override 
  119.  
  120.     //------------------------------------------------------------------------------------
  121.     // Standard signature support.
  122.     //------------------------------------------------------------------------------------
  123.  
  124.     virtual IDType GetStandardSignature();    // override 
  125.         // Returns this class's standard signature.
  126.  
  127.     //------------------------------------------------------------------------------------
  128.     // Stream I/O protocol support.
  129.     //------------------------------------------------------------------------------------
  130.  
  131.     virtual void ReadFields(TStream* aStream);    // override 
  132.     
  133.     virtual void WriteFields(TStream* aStream);    // override 
  134.  
  135.     //------------------------------------------------------------------------------------
  136.     // Imaging
  137.     //------------------------------------------------------------------------------------
  138.  
  139.     virtual Boolean Focus(); // override 
  140.  
  141.     virtual void Draw(const VRect& area); // override 
  142.         // sets a patch to GetResource in certain cases 
  143.  
  144.  
  145.     //------------------------------------------------------------------------------------
  146.     // tracking
  147.     //------------------------------------------------------------------------------------
  148.  
  149.     virtual void DoMouseCommand(VPoint&            theMouse,
  150.                                        TToolboxEvent*    event,
  151.                                        CPoint            hysteresis); // override 
  152.  
  153.     //------------------------------------------------------------------------------------
  154.     // accessors
  155.     //------------------------------------------------------------------------------------
  156.  
  157.     virtual void AttachMenuRef(MenuRef itsMenuRef);
  158.         // attaches itsMenuRef to this popup 
  159.  
  160.     virtual MenuRef GetMenuRef();
  161.         // returns the MenuRef by accessing the control handle's private storage 
  162.         
  163.     virtual void GetMenuLabel(CStr255& itsLabel);
  164.         //  returns the menu label 
  165.  
  166.     virtual CommandNumber GetCurrentCommand();
  167.         // For the currently selected menu item, returns its CommandNumber. 
  168.  
  169.     virtual short GetCurrentItem();
  170.         // Returns the value of the current item.
  171.  
  172.     virtual short GetLastItem();
  173.         // Returns the value of the last selected item.
  174.         // For a hierarchical popup menu, this is different than this->GetCurrentItem().
  175.  
  176.     virtual short GetMenuID();
  177.         // Returns the menu ID of the popup.
  178.         
  179.     virtual short GetLastMenuID();
  180.         // Returns the menu id of the last selected menu.
  181.         // For a hierarchical popup menu, this is different than this->GetMenuID().
  182.             
  183.     virtual void GetItemText(short item, CStr255& theText);
  184.         // Returns in "theText" the text for the specified item in the menu. 
  185.         
  186.     virtual short GetNumberOfItems();
  187.         // Returns the number of items in the menu. 
  188.         
  189.     virtual void GetTitle(CStr255& title);
  190.         // returns the popup's title 
  191.  
  192.     virtual void SetCurrentItem(short item, Boolean redraw);
  193.         // Sets the currently selected item, redrawing if required. 
  194.         
  195.     virtual void SetPopup(MenuRef itsMenuRef,
  196.                                  short itsCurrentItem,
  197.                                  Boolean redraw);
  198.         // Sets the fields of the popup to contain theMenu, with currentItem selected,
  199.         // redrawing if required.
  200.  
  201.     virtual void SetTitle(const CStr255& title);
  202.         // sets the popup's title 
  203.  
  204.     //------------------------------------------------------------------------------------
  205.     // data members
  206.     //------------------------------------------------------------------------------------
  207. public:
  208.     ResType        fUseAddResMenuResType;
  209.     ResNumber    fMenuID;
  210.     ResNumber    fStrListID;                        // popup's title:    STR# rsrc id
  211.     short        fItemOffset;
  212.     short        fTitleJust;
  213.     short        fUseAddResMenuNumberInitialItems;
  214.     short        fIndex;                            //                    index into STR#
  215.     Style        fTitleStyle;
  216.     Boolean        fUseAddResMenu;
  217.     Boolean        fMacAppSetDimState;
  218. };
  219.     
  220. #endif
  221.